package com.yueqian.exception;

import java.util.Arrays;

/**
 * @author shkstart
 * @create 2021-01-14 15:56
 */
public class INN {
    public Object[] teams;
    private int index = -1;

    public INN(int size) {
        teams = new Object[size];
    }

    /*
     * 放入栈
     * */
    public void push(Object team) {
        for (int i = 0; i < teams.length; i++) {
            if (teams[i] == null) {
                teams[i] = team;
                return;
            }
        }
//                System.out.println("你错了");
//            throw new FullINNExecption();
        throw new RuntimeException("你错了");
    }

    /*
     * 取出栈
     * */
    public Object pop() {
        if (teams[0] == null) {
            throw new EmptyINNException();
        }
        Object result = null;
        for (int i = teams.length - 1; i >= 0; i--) {
//            System.out.println("111");
            if (teams[i] == null) {

                continue;
            } else {
                result = teams[i];
                teams[i] = null;
                break;
            }
        }
        return "取出来的" + result;
    }

    @Override
    public String toString() {
        return "INN{" +
                "teams=" + Arrays.toString(teams) +
                '}';
    }
}
